import http from "../utils/request"
import {PageRequestType, ResponseType, PageResponseType} from "../types/Response";
import {AxiosResponse} from "axios";
import {GoodType} from "./GoodRequest";

const apiPrefix:string = "/mainPage";

export interface MainPageType {
    // id
    id?:string|null|undefined
    // 主轮播图
    mainSlideshows?:string|null|undefined|object
    // 底下那几个图片(也可以是轮播图)
    secondaryImages?:string|null|undefined|object
    // 侧边两个图片
    sideImages?:string|null|undefined|object
    // 左边链接
    leftText?:string|null|undefined|object
    // 右边链接
    rightText?:string|null|undefined|object
    // 示例的商品id
    exampleGoodsId?:string|null|undefined
    // 示例的商品
    exampleGoods?:GoodType
    // 创建时间
    createAt?:any|null|undefined
}

export interface MainPagePageSearchType extends PageRequestType, MainPageType {
    current: 1;
    size: 10;
}


export async function addMainPage(data: MainPageType): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        data: data,
        url: apiPrefix,
        method: 'post'
    })
}

export async function deleteMainPageById(id: string): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        params: {
            id
        },
        url: apiPrefix+'/id',
        method: 'delete'
    })
}

export async function deleteMainPageByIds(ids: string[]): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        params: {
            ids
        },
        url: apiPrefix+'/batch',
        method: 'delete'
    })
}


export async function searchMainPageById(id: string): Promise<AxiosResponse<ResponseType<MainPageType>>> {
    return await http.request({
        params: {
            id
        },
        url: apiPrefix+'/id',
        method: 'get'
    })
}

export async function searchMainPageLast(params?: MainPageType): Promise<AxiosResponse<ResponseType<MainPageType>>> {
    return await http.request({
        params: params,
        url: apiPrefix+'/last',
        method: 'get'
    })
}

export async function searchMainPageByPage(params: MainPagePageSearchType): Promise<AxiosResponse<ResponseType<PageResponseType<MainPageType>>>> {
    return await http.request({
        params: params,
        url: apiPrefix+'/page',
        method: 'get'
    })
}


export async function updateMainPageById(data: MainPageType): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        data: data,
        url: apiPrefix,
        method: 'put'
    })
}
